<?php

namespace app\admin\controller;

use app\admin\model\AdminModel;
use app\admin\model\UserModel;
use think\Controller;
use think\Log;

class Admin extends Controller
{
    public function admin_list()
    {
        return $this->fetch('admin_list');
    }

    public function list1()
    {
        $AdminModel = new AdminModel();
        $page = input('param.page');
        $limit = input('param.limit');
        $datalist = $AdminModel->list($page, $limit);
        $count = $AdminModel->count();
        $data = [
            'code' => 0,
            'msg' => 'ok',
            'count' => $count,
            'data' => $datalist
        ];
        return $data;
    }

    public function admin_like()
    {
        $username = input('param.username');
        $AdminModel = new AdminModel();
        $datalist = $AdminModel->like($username);
        $data = [
            'code' => 0,
            'msg' => 'ok',
            'count' => 100,
            'data' => $datalist
        ];
        return $data;
    }


    public function admin_add()
    {
        if (request()->isPost()) {
            $pwd = md5(input('param.pwd'));
            $data = [
                'username' => input('param.username'),
                'pwd' => $pwd,
                'tel' => input('param.tel'),
                'email' => input('param.email'),
                'add_time' => time(),
                'role' => input('param.role'),
                'status' => 0,
            ];
            $AdminModel = new AdminModel();
            $AdminModel->add($data);
        }

        return $this->fetch();
    }


    public function admin_delete()
    {
        if (request()->isGet()) {
            $id = input('param.id');
            $AdminModel = new AdminModel();
            $AdminModel->delete($id);

        }
    }

    public function admin_edit()
    {
        $AdminModel = new AdminModel();
        if (request()->isPost()) {
            $id = input('param.id');
            $data = [
                'username' => input('param.username'),
                'pwd' => input('param.pwd'),
                'tel' => input('param.tel'),
                'email' => input('param.email'),
                'add_time' => time(),
                'role' => input('param.role'),
                'status' => 0,
            ];
            $AdminModel->update($id, $data);
        }
        return $this->fetch();
    }

    public function admin_cate()
    {
        return $this->fetch();
    }


    public function admin_role()
    {
        return $this->fetch();
    }

    public function admin_rule()
    {
        return $this->fetch();
    }
}